//
//  TJOrderDetailHeaderView.m
//  Teleport
//
//  Created by xtjun on 2020/6/14.
//  Copyright © 2020 xtjun. All rights reserved.
//

#import "TJOrderDetailHeaderView.h"


@interface TJOrderDetailHeaderView()
 
@property (weak, nonatomic) UIButton *tipButton;

@end

@implementation TJOrderDetailHeaderView


- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
 
        UILabel *titleLabel = [UILabel lableWithSuperView:self font:MediumFont(24) color:UIColor.blackColor title:@"" textAlignment:NSTextAlignmentCenter];
        [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.offset(20);
            make.left.offset(16);
        }];
 
        UILabel *subTitleLabel = [UILabel lableWithSuperView:self font:UIFont_Px(13) color:UIColor_Hex(0x262626) title:@"" textAlignment:NSTextAlignmentCenter];
        [subTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(titleLabel.mas_bottom).offset(2);
            make.left.equalTo(titleLabel);
        }];
        
        UILabel *stateLabel = [UILabel lableWithSuperView:self font:UIFont_Px(13) color:UIColor_Hex(0x272727) title:@"" textAlignment:NSTextAlignmentCenter];
        [stateLabel shearRoundedCornersWithRadiu:14];
        stateLabel.hidden = YES;
        [stateLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(titleLabel);
            make.right.offset(-16);
            make.height.offset(28);
            make.width.offset(60);
        }];
        
           UIButton *tipButton = [UIButton buttonWithSuperView:self font:UIFont_Px(12) color:UIColor_Hex(0x262626) title:@""];
           [tipButton setImage:[UIImage imageNamed:@"header_tip_icon"] forState:UIControlStateNormal];
           [tipButton setImage:[UIImage imageNamed:@"header_tip_icon"] forState:UIControlStateHighlighted];
           [tipButton setImagePosition:LXMImagePositionLeft spacing:3];
        tipButton.hidden = YES;
           [tipButton setContentHorizontalAlignment:UIControlContentHorizontalAlignmentLeft];
            [tipButton mas_makeConstraints:^(MASConstraintMaker *make) {
               make.width.offset(150);
               make.left.offset(16);
               make.height.offset(30);
                make.top.equalTo(subTitleLabel.mas_bottom).offset(4);
            }];
        
        _titleLabel = titleLabel;
        _stateLabel = stateLabel;
        _subTitleLabel = subTitleLabel;
        _tipButton = tipButton;
        
    }
    return self;
}

- (void)setTip:(NSString *)tip {
    _tip = tip;
    
    _tipButton.hidden = NO;
    [_tipButton setTitle:tip forState:UIControlStateNormal];
    [_tipButton setImagePosition:LXMImagePositionLeft spacing:5];
}


- (void)setSubTitle:(NSString *)subTitle {
    _subTitle = subTitle;
    
    _subTitleLabel.text = subTitle;
    
    if (subTitle) {
        
        [_subTitleLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(_titleLabel.mas_bottom).offset(4);
            make.left.equalTo(_titleLabel);
        }];
        
        [_tipButton mas_remakeConstraints:^(MASConstraintMaker *make) {
           make.width.offset(150);
           make.left.offset(16);
           make.height.offset(30);
            make.top.equalTo(_subTitleLabel.mas_bottom).offset(8);
        }];
        
    } else {
        
        [_subTitleLabel mas_remakeConstraints:^(MASConstraintMaker *make) {

        }];
        
        [_tipButton mas_remakeConstraints:^(MASConstraintMaker *make) {
           make.width.offset(150);
           make.left.offset(16);
           make.height.offset(30);
            make.top.equalTo(_titleLabel.mas_bottom).offset(8);
        }];
        
    }
}

@end
